﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text;
using System.Windows.Forms;
using libgambattebridge;

namespace WindowsFormsApplication1
{
    public partial class GbRenderer : WeifenLuo.WinFormsUI.Docking.DockContent
    {
        GBBridge gb;
        Bitmap bmp;
        byte[] audio;

        public GbRenderer()
        {
            InitializeComponent();
            gb = new GBBridge();
            audio = new byte[1024 * 1024 * 4];
            bmp = new Bitmap(160, 144, PixelFormat.Format32bppRgb);
            gb.setInputGetter(new InputGetterBridge());
        }

        public void LoadFile(string filename) { gb.load(filename); }

        public void Tick()
        {
            uint samples = 1024 * 1024;
            if (gb.runFor(bmp, audio, ref samples) != -1) 
            {
                Invalidate();
            }
        }

        public void Breakpoint()
        {
            gb.breakpoint();
        }

        private void GbRenderer_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.DrawImage(bmp, Width / 2 - 80, Height / 2 - 144 / 2, 160, 144);
        }
    }
}
